<?php
class PersonalApp extends CommonApp {
   
   	//个人信息栏目界面
    public function indexAct(){
        $this->checkLogin();
    	$userid = My::arr2var($_SESSION,'member.memberid');
    	$result = DB('homeuser')->clear()->where("id={$userid}")->find();
    	$result['params'] = My::decodeJson($result['params']);
    	$this->assign('result',$result);
        if($result['type'] == '0')
		    $this->display();
        elseif($result['type'])
            $this->display('Personal/teacher_index');
    }

    //个人信息修改验证
    public function infoAct(){
    	$params = My::arr2var($_POST,'params');
    	if(!My::is_string($_POST['username'],array('c')))
    		$this->ajaxReturn(300,'姓名填写有误！');
    	if(empty($params['class']))
    		$this->ajaxReturn(300,'班级填写有误！');
    	if(!My::is_date($params['birthdate']))
    		$this->ajaxReturn(300,'出生日期填写有误！');
    	if(!My::is_card($params['indentify']))
   			$this->ajaxReturn(300,'身份证填写有误！');
    	if(!My::is_string($params['nation'],array('c')))
    		$this->ajaxReturn(300,'民族填写有误！');
    	if(!My::is_id($params['number']))
    		$this->ajaxReturn(300,'学号填写有误！');
    	if(!My::is_tel($_POST['mobile']))
    		$this->ajaxReturn(300,'手机号码填写有误！');
    	if(!My::is_email($_POST['email']))
    		$this->ajaxReturn(300,'邮箱填写有误！');
    	$userid = My::arr2var($_SESSION,'member.memberid');
        $_POST['editdate'] = date("Y-m-d H:i:s");
    	$ok = DB('homeuser')->clear()->where("id={$userid}")->save($_POST);
    	if($ok>=0)	$this->ajaxReturn(200,"个人信息修改成功");
    	else		$this->ajaxReturn(300,"个人信息修改失败");
    }

    //打印页面数据
    public function print_infoAct(){
        $userid = My::arr2var($_SESSION,'member.memberid');
        $result = DB('homeuser')->clear()->where("id={$userid}")->field('password',true)->find();
        $result['params'] = My::decodeJson($result['params']);
        unset($id);
        $this->assign('result',$result);
        $this->display();
    }
   
    //教师个人信息页
    public function teacher_infoAct(){
        $params = My::arr2var($_POST,'params');
        if(!My::is_string($_POST['username'],array('c')))
            $this->ajaxReturn(300,'姓名填写有误！');
        if(empty($params['age']) || !My::is_id($params['age']))
            $this->ajaxReturn(300,'年龄填写有误！');
        if(!My::is_date($params['birthdate']))
            $this->ajaxReturn(300,'出生日期填写有误！');
        if(!My::is_string($params['political'],array('c')))
            $this->ajaxReturn(300,'政治面貌填写有误！');
        if(!My::is_string($params['nation'],array('c')))
            $this->ajaxReturn(300,'民族填写有误！');
        if(!My::is_string($params['record'],array('c')))
            $this->ajaxReturn(300,'学历填写有误！');
        if(!My::is_string($params['degree'],array('c')))
            $this->ajaxReturn(300,'学位填写有误！');
        if(!My::is_string($params['teacher_type'],array('c')))
            $this->ajaxReturn(300,'导师类型填写有误！');
        if(!My::is_id($params['number']))
            $this->ajaxReturn(300,'工号填写有误！');
        if(!My::is_tel($params['mobile']))
            $this->ajaxReturn(300,'手机号码填写有误！');
        if(!My::is_email($_POST['email']))
            $this->ajaxReturn(300,'邮箱填写有误！');
        if(!My::is_string($params['professional']))
            $this->ajaxReturn(300,'职称填写有误！');
        if(!My::is_string($params['direction']))
            $this->ajaxReturn(300,'研究方向填写写有误！');
        if(!My::is_string($params['faculty'],array('c')))
            $this->ajaxReturn(300,'所属院系填写有误！');
        if(!My::is_string($params['unit']))
            $this->ajaxReturn(300,'单位填写有误！');
        if(!My::is_string($params['address']))
            $this->ajaxReturn(300,'家庭地址填写有误！');
        $userid = My::arr2var($_SESSION,'member.memberid');
        $_POST['editdate'] = date("Y-m-d H:i:s");
        if(isset($_POST['params']['teacher']))
            foreach ($_POST['params']['teacher'] as $key => $value) {
                foreach ($value as $keys => $values) {
                   $_POST['params']['teacher'][$keys][$key] = $values;
                   unset($_POST['params']['teacher'][$key]);
                }
            }
        $ok = DB('homeuser')->clear()->where("id={$userid}")->save($_POST);
        if($ok>=0)  $this->ajaxReturn(200,"个人信息修改成功");
        else        $this->ajaxReturn(300,"个人信息修改失败");
    }

}